package com.goexcursion

import grails.converters.JSON

import com.goexcursion.validator.ParameterValidator

class UserController {

	static allowedMethods = [ list:'GET', create:'POST', update:'UPDATE', delete:'DELETE']
	ParameterValidator parameterValidator
	UserService userService
	
	def create = {
		parameterValidator.validate( request.JSON, "email")
		User user = userService.create(request.JSON.email as String)
		render user as JSON
	}
	
	def update = {
		
	}
	
	def delete = {
		try {
			userService.delete(params.id as Long)
			render(text:'',contentType:'application/json')
		} catch (Exception e) {
			render(text:e.getMessage(),contentType:'application/json')
		}
	}
	
	def list = {
		userService.get(params.id as Long)
	}
}
